import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
import 'package:signage/l10n/l10n.dart';

class EditDialog extends StatelessWidget {
  final String title;
  final String hintText;
  final int maxLength;
  final TextEditingController controller;
  final VoidCallback? onConfirm;
  final VoidCallback? onCancel;

  const EditDialog({
    Key? key,
    required this.title,
    required this.hintText,
    this.maxLength = 50,
    required this.controller,
    this.onConfirm,
    this.onCancel,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Dialog(
      shape: RoundedRectangleBorder(
        borderRadius: BorderRadius.circular(16.r),
      ),
      child: Container(
        decoration: BoxDecoration(
          color: Colors.white,
          borderRadius: BorderRadius.circular(16.r),
        ),
        width: 280.w,
        padding: EdgeInsets.all(20.w),
        child: Column(
          mainAxisSize: MainAxisSize.min,
          children: [
            // 标题栏和关闭按钮
            Row(
              mainAxisAlignment: MainAxisAlignment.center,
              children: [
                Text(
                  title,
                  style: TextStyle(
                    fontSize: 16.sp,
                    color: Color(0xFF333333),
                  ),
                ),
              ],
            ),
            SizedBox(height: 20.h),
            // 输入框
            TextField(
              controller: controller,
              maxLength: maxLength,
              decoration: InputDecoration(
                fillColor: Color(0xFFF7F7F7),
                filled: true,
                hintText: hintText,
                hintStyle: TextStyle(
                  color: Colors.black38,
                  fontSize: 14.sp,
                ),
                border: InputBorder.none,
                enabledBorder: InputBorder.none,
                focusedBorder: InputBorder.none,
                contentPadding: EdgeInsets.symmetric(
                  horizontal: 12.w,
                  vertical: 8.h,
                ),
              ),
            ),
            SizedBox(height: 20.h),
            // 按钮组
            Row(
              mainAxisAlignment: MainAxisAlignment.spaceBetween,
              children: [
                Expanded(
                  child: InkWell(
                    onTap: onCancel ?? () => Get.back(),
                    child: Container(
                      alignment: Alignment.center,
                      padding: EdgeInsets.symmetric(horizontal: 16.w, vertical: 8.h),
                      decoration: BoxDecoration(
                        color: Color(0xFFEFEFEF),
                        borderRadius: BorderRadius.circular(28.r),
                      ),
                      child: Text(
                        AppLocalizations.of(context)!.translate('cancel'),
                        style: TextStyle(
                          fontSize: 14.sp,
                          color: Color(0xFF333333),
                        ),
                      ),
                    ),
                  ),
                ),
                SizedBox(width: 12.w),
                Expanded(
                  child: InkWell(
                    onTap: onConfirm,
                    child: Container(
                      alignment: Alignment.center,
                      padding: EdgeInsets.symmetric(horizontal: 16.w, vertical: 8.h),
                      decoration: BoxDecoration(
                        color: Color(0xFFFCCF01),
                        borderRadius: BorderRadius.circular(28.r),
                      ),
                      child: Text(
                        AppLocalizations.of(context)!.translate('confirm'),
                        style: TextStyle(
                          fontSize: 14.sp,
                          color: Color(0xFF333333),
                        ),
                      ),
                    ),
                  ),
                ),
              ],
            ),
          ],
        ),
      ),
    );
  }
}

class TipsDialog extends StatelessWidget {
  final String title;
  final String text;
  final String confirmText;
  final VoidCallback? onConfirm;
  final VoidCallback? onCancel;
  final String cancelText;
  final bool showCancel;
  const TipsDialog({
    Key? key,
    required this.title,
    required this.text,
    this.confirmText = '',
    this.cancelText = '',
    this.onConfirm,
    this.onCancel,
    this.showCancel = false,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Dialog(
      shape: RoundedRectangleBorder(
        borderRadius: BorderRadius.circular(16.r),
      ),
      child: Container(
        decoration: BoxDecoration(
          color: Colors.white,
          borderRadius: BorderRadius.circular(16.r),
        ),
        width: 280.w,
        padding: EdgeInsets.all(20.w),
        child: Column(
          mainAxisSize: MainAxisSize.min,
          children: [
            // 标题栏和关闭按钮
            Row(
              mainAxisAlignment: MainAxisAlignment.center,
              children: [
                Text(
                  title,
                  style: TextStyle(
                    fontSize: 16.sp,
                    color: Color(0xFF333333),
                  ),
                ),
              ],
            ),
            SizedBox(height: 20.h),
            // 输入框
            Text(
              text,
              style: TextStyle(
                color: Colors.black38,
                fontSize: 14.sp,
              ),
            ),
            SizedBox(height: 20.h),
            // 按钮组
            Row(
              mainAxisAlignment: MainAxisAlignment.spaceBetween,
              children: [
                if (showCancel)
                 Expanded(
                  child: InkWell(
                    onTap: onCancel ?? () => Get.back(),
                    child: Container(
                      alignment: Alignment.center,
                      padding:
                          EdgeInsets.symmetric(horizontal: 16.w, vertical: 8.h),
                      decoration: BoxDecoration(
                        color: Color(0xFFEFEFEF),
                        borderRadius: BorderRadius.circular(28.r),
                      ),
                      child: Text(
                        cancelText.isEmpty ? AppLocalizations.of(Get.context!)!.translate('cancel') : cancelText,
                        style: TextStyle(
                          fontSize: 14.sp,
                          color: Color(0xFF333333),
                        ),
                      ),
                    ),
                  ),
                ),
                if (showCancel) SizedBox(width: 12.w),
                Expanded(
                  child: InkWell(
                    onTap: onConfirm ?? () => Get.back(),
                    child: Container(
                      alignment: Alignment.center,
                      padding:
                          EdgeInsets.symmetric(horizontal: 16.w, vertical: 8.h),
                     decoration: BoxDecoration(
                        color: Color(0xFFFCCF01),
                        borderRadius: BorderRadius.circular(28.r),
                      ),
                      child: Text(
                        confirmText.isEmpty ? AppLocalizations.of(Get.context!)!.translate('confirm') : confirmText,
                        style: TextStyle(
                          fontSize: 14.sp,
                          color: Color(0xFF33F3333),
                        ),
                      ),
                    ),
                  ),
                ),
                SizedBox(width: 12.w),
              ],
            ),
          ],
        ),
      ),
    );
  }
}
